export default {
  mounted(el: HTMLElement, binding: any) {
    const { origin } = binding.value ?? {};
    const rect = el.getBoundingClientRect();
    const parentRect =
      el.parentElement!.getBoundingClientRect() ??
      document.body.getBoundingClientRect();
    // 计算出缩放比例，哪边短就按照哪边缩放
    const scale = Math.min(
      parentRect.width / rect.width,
      parentRect.height / rect.height
    );
    el.style.transform = `scale(${scale})`;
    if (origin) el.style.transformOrigin = origin;
  },
};
